/*
 * 文件名： WcPayResMsg.java
 * 
 * 工程名称: common-domain
 *
 * Gopay
 *
 * 创建日期： 2016年10月11日
 *
 * Copyright(C) 2016, by www.gopay.com.cn Inc.All rights reserved.
 *
 * 原始作者: 宣广海
 *
 */
package com.gopay.common.domain.bank.wechat.wcpay.citic.res;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.gopay.common.domain.bank.WcPayBaseMessage;
import com.thoughtworks.xstream.annotations.XStreamAlias;

/**
 * 公众号退款查询同步结果返回
 *
 * @author jianglijun
 *
 * @version
 *
 * @since 2016年10月17日
 */
@XStreamAlias("xml")
public class WcRefundQueryResMsg extends WcPayBaseMessage {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -3788957776460616416L;
	
	private String appid;
	private String trade_type;
	/**
	 * 版本号
	 */
	private String version;
	/**
	 * 字符集
	 */
	private String charset;
	/**
	 * 签名方式
	 */
	private String sign_type;
	/**
	 * 返回状态码 0 表示成功非 0 表示失败 此字段是通信标识，非交易 标识，交易是否成功需要查 看result_code 来判断
	 */
	private String status;
	/**
	 * 返回信息
	 */
	private String message;

	// 以下字段在 status 为 0 的时候有返回
	/**
	 * 业务结果 0 表示成功非 0 表示失败
	 */
	private String result_code;
	/**
	 * 商户号
	 */
	private String mch_id;
	/**
	 * 设备号
	 */
	private String device_info;
	/**
	 * 随机字符串
	 */
	private String nonce_str;
	/**
	 * 错误代码
	 */
	private String err_code;
	
    /**
     * 错误描述
     */
    private String err_msg;

	/**
	 * 签名
	 */
	private String sign;

	/**
	 * 威富通订单号
	 */
	private String transaction_id;
	/**
	 * 商户订单号
	 */
	private String out_trade_no;

	/**
	 * 退款笔数
	 */
	private int refund_count;

	private List<WcRefundItem> refundItems;
	private String out_transaction_id;
	private String trade_state_desc;
	private String total_fee;
	/**
	 * 因响应报文退款内容的元素名称不确定，因此需要将<out_refund_no_$n>元素之前的
	 * xml报文截取出来，并转换成SdkRefundQueryResMsg类对象,之后将剩余的xml
	 * 报文通过该方法映射为该类的集合元素
	 * @param itemString 退款查询响应xml报文</refund_count>元素之后的
	 * 所有xml元素的字符串
	 */
	public void fillItem(String itemString) {
		refundItems = new ArrayList<WcRefundItem>(refund_count);
		for (int i = 0; i < refund_count; i++) {
			WcRefundItem item = new WcRefundItem();
			if (itemString.contains("<out_refund_no_" + i + ">")) {
				item.setOut_refund_no(StringUtils.substringBetween(itemString, "<out_refund_no_" + i + "><![CDATA[", "]]></"));
			}
			if (itemString.contains("<refund_id_" + i + ">")) {
				item.setRefund_id(StringUtils.substringBetween(itemString, "<refund_id_" + i + "><![CDATA[", "]]></"));
			}
			if (itemString.contains("<refund_channel_" + i + ">")) {
				item.setRefund_channel(StringUtils.substringBetween(itemString, "<refund_channel_" + i + "><![CDATA[", "]]></"));
			}
			if (itemString.contains("<refund_fee_" + i + ">")) {
				item.setRefund_fee(StringUtils.substringBetween(itemString, "<refund_fee_" + i + "><![CDATA[", "]]></"));
			}
			if (itemString.contains("<coupon_refund_fee_" + i + ">")) {
				item.setCoupon_refund_fee(StringUtils.substringBetween(itemString, "<coupon_refund_fee_" + i + "><![CDATA[", "]]></"));
			}
			if (itemString.contains("<refund_time_" + i + ">")) {
				item.setRefund_time(StringUtils.substringBetween(itemString, "<refund_time_" + i + "><![CDATA[", "]]></"));
			}
			if (itemString.contains("<refund_status_" + i + ">")) {
				item.setRefund_status(StringUtils.substringBetween(itemString, "<refund_status_" + i + "><![CDATA[", "]]></"));
			}
			refundItems.add(item);
		}
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getCharset() {
		return charset;
	}

	public void setCharset(String charset) {
		this.charset = charset;
	}

	public String getSign_type() {
		return sign_type;
	}

	public void setSign_type(String sign_type) {
		this.sign_type = sign_type;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getResult_code() {
		return result_code;
	}

	public void setResult_code(String result_code) {
		this.result_code = result_code;
	}

	public String getMch_id() {
		return mch_id;
	}

	public void setMch_id(String mch_id) {
		this.mch_id = mch_id;
	}

	public String getDevice_info() {
		return device_info;
	}

	public void setDevice_info(String device_info) {
		this.device_info = device_info;
	}

	public String getNonce_str() {
		return nonce_str;
	}

	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}

	public String getErr_code() {
		return err_code;
	}

	public void setErr_code(String err_code) {
		this.err_code = err_code;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getTransaction_id() {
		return transaction_id;
	}

	public void setTransaction_id(String transaction_id) {
		this.transaction_id = transaction_id;
	}

	public String getOut_trade_no() {
		return out_trade_no;
	}

	public void setOut_trade_no(String out_trade_no) {
		this.out_trade_no = out_trade_no;
	}

	public int getRefund_count() {
		return refund_count;
	}

	public void setRefund_count(int refund_count) {
		this.refund_count = refund_count;
	}

	public List<WcRefundItem> getRefundItems() {
		return refundItems;
	}

	public void setRefundItems(List<WcRefundItem> refundItems) {
		this.refundItems = refundItems;
	}

	public String getErr_msg() {
		return err_msg;
	}

	public void setErr_msg(String err_msg) {
		this.err_msg = err_msg;
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getTrade_type() {
		return trade_type;
	}

	public void setTrade_type(String trade_type) {
		this.trade_type = trade_type;
	}

	public String getOut_transaction_id() {
		return out_transaction_id;
	}

	public void setOut_transaction_id(String out_transaction_id) {
		this.out_transaction_id = out_transaction_id;
	}

	public String getTrade_state_desc() {
		return trade_state_desc;
	}

	public void setTrade_state_desc(String trade_state_desc) {
		this.trade_state_desc = trade_state_desc;
	}

	public String getTotal_fee() {
		return total_fee;
	}

	public void setTotal_fee(String total_fee) {
		this.total_fee = total_fee;
	}
}
